public with sharing class MobileAppEditRequestExtension
{
    public List<Requested_For__c> bankNamesList {get; set;}
    public List<Requested_For__c> etisalatServicesList {get; set;}
    public List<Requested_For__c> purposeOfVisitList {get; set;}
    public List<Requested_For__c> addressToEmbassyList {get; set;}
    public List<Requested_For__c> freeZonesNamesList {get; set;}
    public List<Requested_For__c> portsNamesList {get; set;}
    public List<Requested_For__c> lostDocumentTypeList {get; set;}
    public List<Requested_For__c> customsClarificationRequestTypeList {get; set;}
    public List<Requested_For__c> customsCodeNumberRequestTypeList {get; set;}
    public List<Requested_For__c> drivingLicenseIssuedEmiratesList {get; set;}
    public List<Requested_For__c> emiratesList {get; set;}
    public List<Requested_For__c> vehicleTypesList {get; set;}
    public List<Requested_For__c> productsList {get; set;}
    public List<Country__c> visitingCountryList {get; set;}
    public List<Country__c> courierCountryList {get; set;}
    public List<Country__c> activeCountryList {get; set;}
    public List<Contact> employeesList {get; set;}
    public List<Occupation__c> occupationList {get; set;}
    public List<Tenancy_Contract__c> activeTenancyContractList {get; set;}
    public String ajmanTrafficDepartmentId {get; set;}
    public String ajmanPoliceDepartmentId {get; set;}
    
    public MobileAppEditRequestExtension()
    {
        
    }
    
    public MobileAppEditRequestExtension(ApexPages.StandardController controller) 
    {
        //Initialize
        bankNamesList = new List<Requested_For__c>();
        etisalatServicesList = new List<Requested_For__c>();
        purposeOfVisitList = new List<Requested_For__c>();
        addressToEmbassyList = new List<Requested_For__c>();
        freeZonesNamesList = new List<Requested_For__c>();
        portsNamesList = new List<Requested_For__c>();
        lostDocumentTypeList = new List<Requested_For__c>();
        customsClarificationRequestTypeList = new List<Requested_For__c>();
        customsCodeNumberRequestTypeList = new List<Requested_For__c>();
        drivingLicenseIssuedEmiratesList = new List<Requested_For__c>();
        emiratesList = new List<Requested_For__c>();
        vehicleTypesList = new List<Requested_For__c>();
        productsList = new List<Requested_For__c>();
        visitingCountryList = new List<Country__c>();
        courierCountryList = new List<Country__c>();
        activeCountryList = new List<Country__c>();
        ajmanTrafficDepartmentId = '';
        ajmanPoliceDepartmentId = '';
        
        //Types to query for
        List<String> requestedForTypes = new List<String>();
        requestedForTypes.add('Banks');
        requestedForTypes.add('Etisalat Services');
        requestedForTypes.add('Purpose of Visit');
        requestedForTypes.add('Embassy');
        requestedForTypes.add('Free Zone');
        requestedForTypes.add('Port');
        requestedForTypes.add('Lost Documents');
        requestedForTypes.add('Customs Clarification');
        requestedForTypes.add('Customs Code Number');
        requestedForTypes.add('Emirates');
        requestedForTypes.add('Vehicle Type');
        requestedForTypes.add('Vehicle');
        requestedForTypes.add('Lost Document Address To');
        requestedForTypes.add('Certificate of Origin');
        
        if(requestedForTypes.size() > 0)
        {
            for(Requested_For__c requestedForObject : [SELECT Id, Name, Type__c FROM Requested_For__c WHERE isActive__c = true AND Type__c IN :requestedForTypes ORDER BY Name])
            {
                if(requestedForObject.Type__c == 'Banks')
                {
                    bankNamesList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Etisalat Services')
                {
                    etisalatServicesList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Purpose of Visit')
                {
                    purposeOfVisitList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Embassy')
                {
                    addressToEmbassyList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Free Zone')
                {
                    freeZonesNamesList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Port')
                {
                    portsNamesList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Lost Documents')
                {
                    lostDocumentTypeList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Customs Clarification')
                {
                    customsClarificationRequestTypeList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Customs Code Number')
                {
                    customsCodeNumberRequestTypeList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Emirates')
                {
                    drivingLicenseIssuedEmiratesList.add(requestedForObject);
                    emiratesList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Vehicle Type')
                {
                    vehicleTypesList.add(requestedForObject);
                }
                else if (requestedForObject.Type__c == 'Vehicle')
                {
                    if(requestedForObject.Name == 'Ajman Traffic Department')
                        ajmanTrafficDepartmentId = requestedForObject.Id;
                }
                else if (requestedForObject.Type__c == 'Lost Document Address To')
                {
                    if(requestedForObject.Name == 'Ajman Police Department')
                        ajmanPoliceDepartmentId = requestedForObject.Id;
                }
                else if (requestedForObject.Type__c == 'Certificate of Origin')
                {
                    productsList.add(requestedForObject);
                }
            }
        }
        
        for(Country__c countryObject : [SELECT Id, Name FROM Country__c ORDER BY Name])
        {
            activeCountryList.add(countryObject);
            
            if(countryObject.Name == 'United Arab Emirates')
                courierCountryList.add(countryObject);
                
            if(countryObject.Name != 'Israel' &&
               countryObject.Name != 'United Arab Emirates')
               visitingCountryList.add(countryObject);
        }
        
        /*
        bankNamesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Banks' AND isActive__c = true ORDER BY Name];
        etisalatServicesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Etisalat Services' AND isActive__c = true ORDER BY Name];
        purposeOfVisitList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Purpose of Visit' AND isActive__c = true ORDER BY Name];
        addressToEmbassyList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Embassy' AND isActive__c = true ORDER BY Name];
        freeZonesNamesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Free Zone' AND isActive__c = true ORDER BY Name];
        portsNamesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Port' AND isActive__c = true ORDER BY Name];
        lostDocumentTypeList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Lost Documents' AND isActive__c = true ORDER BY Name];
        customsClarificationRequestTypeList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Customs Clarification' AND isActive__c = true ORDER BY Name];
        customsCodeNumberRequestTypeList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Customs Code Number' AND isActive__c = true ORDER BY Name];
        drivingLicenseIssuedEmiratesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Emirates' AND isActive__c = true ORDER BY Name];
        emiratesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Emirates' AND isActive__c = true ORDER BY Name];
        vehicleTypesList = [SELECT Id, Name FROM Requested_For__c WHERE Type__c = 'Vehicle Type'];
        
        visitingCountryList = [SELECT Id, Name FROM Country__c WHERE Name NOT IN ('Israel', 'United Arab Emirates') ORDER BY Name];
        courierCountryList = [SELECT Id, Name FROM Country__c WHERE Name = 'United Arab Emirates' ORDER BY Name];
        activeCountryList = [SELECT Id, Name FROM Country__c ORDER BY Name];
        */
        
        occupationList = new List<Occupation__c>([SELECT Id, Name FROM Occupation__c WHERE Is_Active__c = true ORDER BY Name]);
        
        /*
        List<Requested_For__c> tempList = [SELECT Id FROM Requested_For__c WHERE Name = 'Ajman Traffic Department' AND Type__c = 'Vehicle' LIMIT 1];
        if(tempList.size() > 0)
            ajmanTrafficDepartmentId = tempList[0].Id;
        */
        
        List<Contact> contactList = new List<Contact> 
            								([SELECT Id, Name, Current_Employer__c 
                                             FROM Contact 
                                             WHERE Id IN (Select ContactId FROM User WHERE Id = :UserInfo.getUserId())
                                             LIMIT 1]);
        
        Contact currentContact = null;
        
        if (contactList.size() > 0)
        	currentContact = contactList[0];
        else
            currentContact = new Contact();
        
        employeesList = new List<Contact>([SELECT Id, Name FROM Contact WHERE Current_Employer__c = :currentContact.Current_Employer__c]);
        
        activeTenancyContractList = new List<Tenancy_Contract__c>
                                    ([SELECT Id, Location__r.Id, Location__r.Name
                                    FROM Tenancy_Contract__c
                                    WHERE Tenant__c = :currentContact.Current_Employer__c
                                    AND Tenancy_Contract_Cancellation_Date__c = null]);
    }
    
    /*
    public String getAjmanTrafficDepartmentId()
    {
        return ajmanTrafficDepartmentId;
    }
    
    public List<Requested_For__c> getVehicleTypesList()
    {
        return vehicleTypesList;
    }
    
    public List<Requested_For__c> getEmiratesList()
    {
        return emiratesList;
    }
    
    public List<Requested_For__c> getDrivingLicenseIssuedEmiratesList()
    {
        return drivingLicenseIssuedEmiratesList;
    }
    
    public List<Country__c> getActiveCountryList()
    {
        return activeCountryList;
    }
    
    public List<Tenancy_Contract__c> getActiveTenancyContractList()
    {
        return activeTenancyContractList;
    }
    
    public List<Occupation__c> getOccupationList()
    {
        return occupationList;
    }
    
    public List<Requested_For__c> getCustomsCodeNumberRequestTypeList()
    {
        return customsCodeNumberRequestTypeList;
    }
    
    public List<Requested_For__c> getCustomsClarificationRequestTypeList()
    {
        return customsClarificationRequestTypeList;
    }
    
    public List<Requested_For__c> getPortsNamesList()
    {
        return portsNamesList;
    }
    
    public List<Requested_For__c> getFreeZonesNamesList()
    {
        return freeZonesNamesList;
    }
    
    public List<Requested_For__c> getBankNamesList()
    {
        return bankNamesList;
    }
    
    public List<Requested_For__c> getEtisalatServicesList()
    {
        return etisalatServicesList;
    }
    
    public List<Requested_For__c> getPurposeOfVisitList()
    {
        return purposeOfVisitList;
    }
    
    public List<Requested_For__c> getAddressToEmbassyList()
    {
        return addressToEmbassyList;
    }
    
    public List<Requested_For__c> getLostDocumentTypeList()
    {
        return lostDocumentTypeList;
    }
    
    public List<Country__c> getVisitingCountryList()
    {
        return visitingCountryList;
    }
    
    public List<Country__c> getCourierCountryList()
    {
        return courierCountryList;
    }
    
    public List<Contact> getEmployeesList()
    {
        return employeesList;
    }
    */
}